let app = getApp();
Page({
    data:{
         isCollect:false,
         header:{},
         userInfo:{},
          imgUrls: [
            {
              url:'http://qn.shebeib.com/11108e3e317028cf3d31fde3f3a133d.jpg'
            }
          ],
          indicatorDots: false,
          autoplay: true,
          interval: 5000,
          duration: 1000,
          obj:{

          },
          productList:[],
          imageList:[],
          showImageDetail:false,
          num:0,
          showListTuiJian:[],
          isButler:false
    },
    onClose:function(){
       this.setData({
           showImageDetail:false
           

        })
    },
    onLeft:function(){

      var num=this.data.num-1;
      if (num==-1) {
        num=this.data.imageList.length-1
      }

      this.setData({
        num:num
      })
    },
     onRight:function(){
      var num=this.data.num+1
       if (num==this.data.imageList.length) {
        num=0
      }
      this.setData({
        num:num
      })
    },
    showImage:function(e){
       console.log('e.currentTarget.dataset.code')
      console.log(e)
        this.setData({
           showImageDetail:true,
           imageList:e.currentTarget.dataset.code,
           num:e.currentTarget.dataset.num

        })
    },
    onLoad:function(options){
        // 生命周期函数--监听页面加载
        console.log("options.id")
        console.log(options);
        this.setData({
            equId:options.id,
            type:options.type
        })
          getApp().getUserInfo().then(res=>{
          var header={
                 'openid':res.openid, //公用请求头
                 'content-type': 'application/json'
             }
           wx.setStorageSync('userInfo', res)

           this.getDeviceDetail(options.id);
           this.getDeviceDetail1(options.id);
           this.getDeviceDetail2(options.id);
           this.getDeviceDetail3(options.id);

           this.isCollect(options.id);
           this.looK(options.id);
           this.getButler();

     })
       
       
    },
     //获取严选机类型
    getButler:function(openid){
      var _self=this;

      wx.request({
            url:getApp().globalData.baseUrl+'/wx/yxj/butler',
            method:"get",
            header:{
                'openid':openid, //公用请求头
                'content-type': 'application/json'
              },
            data:{
              openid:openid
            },
            success: function(res) {
            console.log(res)  
            if (res.data.code==200) {
               if (res.data.obj) {
                  _self.setData({
                    isButler:true,
                    butler:res.data.obj
                  })
                }else{
                  _self.setData({
                    isButler:false
                  })
                }
            }else{
              _self.setData({
                    isButler:false
              })
              
            }
            
         }
       })   
    },
    turnTaTa:function(e){
       console.log(e.currentTarget.dataset.code)
         wx.navigateTo({
            url: '/pages/tataSheBei-s/mineSheBei?openid='+e.currentTarget.dataset.code
        })

    },
    looK:function (id) {
      var userInfo= wx.getStorageSync('userInfo');
      var url
      url=getApp().globalData.baseUrl + '/wx/equipment/browse/save'
       var _self=this;
         wx.request({
            url: url,
            method:"POST",
            data:{
              openid:userInfo.openid,
              equId:id
            },
            header: {
                'openid':userInfo.openid, //公用请求头
                'content-type': 'application/json'
            },
            success: function(res) {
             console.log(res)
            
            
           
         }
       })
        
    },

    
    getLeiSiDetail:function (type,province) {
       var userInfo= wx.getStorageSync('userInfo');
      var url
      url=getApp().globalData.baseUrl + '/wx/equipment/getList?status=20&type='+type+'&province='+province
       var _self=this;
         wx.request({
            url: url,
            method:"GET",
            header: {
                'openid':userInfo.openid, //公用请求头
                'content-type': 'application/json'
            },
            success: function(res) {
             console.log(res)
             _self.setData({
              productList:res.data.obj.list
             })
            
           
         }
       })
    },
    //获取基础信息
    getDeviceDetail:function (id) {
        var userInfo= wx.getStorageSync('userInfo');
         var _self=this;
         wx.request({
            url:getApp().globalData.baseUrl+'/wx/yxj/equipment/info?id='+id+"&openid="+userInfo.openid,
            method:"GET",
            header: {
                'openid':userInfo.openid, //公用请求头
                'content-type': 'application/json'
            },
            success: function(res) {
             // _self.getLeiSiDetail(res.data.obj.type,res.data.obj.province);
             console.log(res.data.obj)
             _self.getButler(res.data.obj.openid)
             res.data.obj.url=[res.data.obj.url]
             _self.setData({
                obj:res.data.obj
             })
            
             _self.getAllSheBeiForTuiJian();
         }
       })
    },
     //获取图片+内容
     getDeviceDetail1:function (id) {
        var userInfo= wx.getStorageSync('userInfo');
         var _self=this;
         wx.request({
            url:getApp().globalData.baseUrl+'/wx/yxj/equipment/auth/content?id='+id+"&openid="+userInfo.openid,
            method:"GET",
            header: {
                'openid':userInfo.openid, //公用请求头
                'content-type': 'application/json'
            },
            success: function(res) {
             // _self.getLeiSiDetail(res.data.obj.type,res.data.obj.province);
             console.log(res.data.obj)
             res.data.obj.url=[res.data.obj.url]
             _self.setData({
                obj1:res.data.obj
             })
            
           
         }
       })
    },
    //获取验证5项
     getDeviceDetail2:function (id) {
        var userInfo= wx.getStorageSync('userInfo');
         var _self=this;
         wx.request({
            url:getApp().globalData.baseUrl+'/wx/yxj/equipment/auth?id='+id+"&openid="+userInfo.openid,
            method:"GET",
            header: {
                'openid':userInfo.openid, //公用请求头
                'content-type': 'application/json'
            },
            success: function(res) {
             // _self.getLeiSiDetail(res.data.obj.type,res.data.obj.province);
             console.log(res.data.obj)
             res.data.obj.url=[res.data.obj.url]
             _self.setData({
                obj2:res.data.obj
             })
            
           
         }
       })
    },
    //更多检测项
     getDeviceDetail3:function (id) {
        var userInfo= wx.getStorageSync('userInfo');
         var _self=this;
         wx.request({
            url:getApp().globalData.baseUrl+'/wx/yxj/equipment/auth/info?id='+id+"&openid="+userInfo.openid,
            method:"GET",
            header: {
                'openid':userInfo.openid, //公用请求头
                'content-type': 'application/json'
            },
            success: function(res) {
             // _self.getLeiSiDetail(res.data.obj.type,res.data.obj.province);
             console.log(res.data.obj)
             res.data.obj.url=[res.data.obj.url]
             _self.setData({
                obj3:res.data.obj
             })
            
           
         }
       })
    },
    onReady:function(){
        // 生命周期函数--监听页面初次渲染完成
       
    },
    onShow:function(){
      
      
    },
    onHide:function(){
        // 生命周期函数--监听页面隐藏
        
    },
    onUnload:function(){
        // 生命周期函数--监听页面卸载
       
    },
    onPullDownRefresh: function() {
        // 页面相关事件处理函数--监听用户下拉动作
      
    },
    onReachBottom: function() {
        // 页面上拉触底事件的处理函数
       
    },
    turnPage:function(){
        if (this.data.type) {

           wx.switchTab({
                  url: '../../pages/home/home'
           })
           return
        }
        
        wx.navigateTo({
            url:'/pages/sendSheBei/sendSheBei'
        })
    },
    callPhone:function(e){
         

        wx.makePhoneCall({
          phoneNumber: this.data.butler.phone //仅为示例，并非真实的电话号码
        })
    },

    //收藏
    collectequ:function () {
        ///wx/collectequ/user/delete
        ///wx/collectequ/user/save
      var userInfo= wx.getStorageSync('userInfo');
      console.log(123)
      var id=this.data.equId;
      var url='',type='';
      if (this.data.isCollect) {
        url='/wx/collectequ/user/delete';
        type="DELETE";
      }else{
        url='/wx/collectequ/user/save';
        type="GET";
      }
        var _self=this;
         wx.request({
            url:getApp().globalData.baseUrl+url+'?equId='+id+'&openid='+userInfo.openid,
            method:type,
            header: {
                'openid':userInfo.openid, //公用请求头
                'content-type': 'application/json'
            },
            success: function(res) {
           
             console.log(res.data.obj)
             _self.setData({
                obj:res.data.obj
             })
           
           
         }
       })
    },
    isCollect:function (id) {
        var userInfo= wx.getStorageSync('userInfo');
        var _self=this;
         wx.request({
            url:getApp().globalData.baseUrl+'/wx/collectequ/user?equId='+id+'&openid='+userInfo.openid,
            method:"GET",
            header: {
                'openid':userInfo.openid, //公用请求头
                'content-type': 'application/json'
            },
            success: function(res) {
           
             console.log(res)
             if (res.data.code==200) {

             }else{
                _self.setData({
                    isCollect:false
                })
             }
            
           
         }
       })
        // body...
    },
     eredarClick (e) { // 达人详情
      var id=e.currentTarget.dataset.code;
    
      wx.navigateTo({
            url: '/pages/eredarDetail/eredarDetail?openid='+id 
        })
    },
    getAllSheBeiForTuiJian:function(province){
      
      var userInfo= wx.getStorageSync('userInfo');
      var url;
      url=getApp().globalData.baseUrl + '/wx/yxj/equipment/getList?current=1&status=20&pagesize=100&province='+this.data.obj.province
    
       var _self=this;
         wx.request({
            url: url,
            method:"GET",
            header: {
                'openid':userInfo.openid, //公用请求头
                'content-type': 'application/json'
            },
            success: function(res) {
             console.log(res.data.obj.list)
             if (res.data.obj.list.length==0) {
               _self.getAll();
               return
             }
             _self.setData({
              showListTuiJian:res.data.obj.list
             })
           
           
         }
       })

    },
    onShareAppMessage:function(){
      var str='';
      if(this.data.obj.price==0){
          str='面议'
      }else{
          str=this.data.obj.price+'万'
      }

         return {
              title: this.data.obj.title,
              path: '/pages/newDeviceDetail/newDeviceDetail?id='+this.data.equId+"&type=share"
            }
    },
    onShareTimeline:function(){
      var str='';
      if(this.data.obj.price==0){
          str='面议'
      }else{
          str=this.data.obj.price+'万'
      }

         return {
              title: this.data.obj.title,
              path: '/pages/newDeviceDetail/newDeviceDetail?id='+this.data.equId+"&type=share"
            }
    },
    turnDetailInfo:function(e){
     var userInfo= wx.getStorageSync('userInfo');
      wx.navigateTo({
            url: '/pages/detailInfo/detailInfo?type='+this.data.equId+'&openid='+userInfo.openid
        })
    }
   
})